package com.king.java.tools.network;


import com.king.java.tools.network.entity.NetworkInfo;
import com.king.java.tools.network.impl.GeneralNetworkUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.math.BigDecimal;
import java.net.InetAddress;
import java.util.List;

/**
 * 描述:
 *
 * @author : sujinchen
 * @date : 2020/10/11
 */
public class NetworkUtilsTest {
    private Logger log = LoggerFactory.getLogger(NetworkUtilsTest.class);
    /**
     * IPv4由32位二进制数组成，分为四组，IPv4地址总数是2^32。一般可用十进制转化后表达。
     */
    public void countIPv4() {
        double getValue = Math.pow(2, 32);
        BigDecimal IPv4 = new BigDecimal(getValue);
        //output>>4294967296
        log.info(IPv4.toString());
    }

    /**
     * IPv6由128位二进制数组成，分为8组，IPv6地址总数是2^128。一般可用十六进制转化后表达。
     */
    public void countIPv6() {
        double getValue = Math.pow(2, 128);
        BigDecimal IPv6 = new BigDecimal(getValue);
        //output>>340282366920938463463374607431768211456
        log.info(IPv6.toString());
    }

    /**
     * 展示当前设备可用的网络连接设备
     */
    public void showUsefulNetworkInterfacesInfo() {
        GeneralNetworkUtils utils = new GeneralNetworkUtils();
        for (NetworkInfo networkInfo:
                utils.getUsefulNetworkInfo()) {
            log.info(networkInfo.toString());
        }
    }
    public static void main(String[] args) {
        NetworkUtils utils = new GeneralNetworkUtils();
        List<InetAddress> usefulIPv4 = utils.getUsefulIPv4();
        System.out.println(usefulIPv4.toString());

    }

}